package com.ducks;

import com.behaviors.FlyBehavior;
import com.behaviors.QuackBehavior;

/**
 * @author SnowmanAndBee
 * @version <version>
 * <description>
 * @date 2021/10/24 - 21:42
 */
public abstract class Duck {
    /**
     * 将行为封装
     */
    QuackBehavior quackBehavior;
    FlyBehavior flyBehavior;

    public abstract void display();

    public void performFly() {
        flyBehavior.fly();
    }
    /**
     * 鸭子对象不亲自处理叫的行为
     */
    public void performQuack() {
        quackBehavior.quack();
    }

    public void swim() {
        System.out.println("All ducks float, even decoys!");
    }
    /**
     * 动态设定行为
     */
    public void setFlyBehavior(FlyBehavior fb) {
        flyBehavior = fb;
    }

    public void setQuackBehavior(QuackBehavior qb) {
        quackBehavior = qb;
    }
}
